﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Include_Admin : AdminBase
{
    Navigation objNavagition = new Navigation();
    public int RootID
    {
        get { return DongDong.Common.Misc.ConvertToInt(ViewState["_RootID"]); }
        set { ViewState["_RootID"] = value; }

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AdminUser objAdminUser = AdminUser.GetCurrent();
            lblNowUser.Text = objAdminUser.UserName;
            RootID = DongDong.Common.Misc.GetQueryStringAsInt("RootID");
            if (RootID == 0)
            {
                string URL = HttpContext.Current.Request.Path.ToString();
                Navigation objNava = Navigation.GetByURL(URL);
                if (objNava != null)
                    RootID = objNava.RootID;
            }
            PopulateNava(objAdminUser.RoleID);
            List<ZNXX> ZNXXs = ZNXX.GetAllByConditon(0, objAdminUser.ID, "", "", 0, "", (int)ZNXX.ZXXXType.后台);
            lblMessCount.Text = ZNXXs.Count.ToString();
            lblNoRead.Text = ZNXXs.Where(row => row.Status == (int)ZNXX.statusXX.未读).ToList().Count.ToString();
        }
    }

    public void PopulateNava(int RoleID)
    {
        rptParentNava.DataSource = Navigation.GetAllRootNavaByAdminRoleID(RoleID);
        rptParentNava.DataBind();
    }



    protected void rptParentNava_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Literal litCSS = (Literal)e.Item.FindControl("litCSS");
            HiddenField hdlID = (HiddenField)e.Item.FindControl("hdlID");
            if (RootID == 0)
            {
                if (e.Item.ItemIndex == 0)
                    litCSS.Text = "lion";
            }
            else
            {
                objNavagition = Navigation.Get(DongDong.Common.Misc.ConvertToInt(hdlID.Value));
                if (RootID == objNavagition.ID) litCSS.Text = "lion";
            }
        }
    }

    protected void btnLogOut_Click(object sender, ImageClickEventArgs e)
    {
        HttpContext.Current.Session["AdminNava"] = null;
        HttpContext.Current.Session["URL"] = null;
        AdminUser.ClearCurrent();
        Response.Redirect("/Admin/AdminLogin.aspx");

    }
}
